package Java.BlackHorse.File;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.util.Arrays;

public class FileDemo7 {
    /*利用文件名过滤器获取当前路径下所有内容
    * public File[] listFiles(FileFilter filter)
    * 利用文件名过滤器获取当前该路径下所有内容
    * public File[] listFiles(FilenameFilter filter)
    * */
    public static void main(String[] args) {
        File file = new File("File");

        File[] files = file.listFiles();
        System.out.println(Arrays.toString(files));

        File[] files2 = file.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.isFile() && pathname.getName().endsWith(".java");
            }
        });
        System.out.println(Arrays.toString(files2));

        File[] files3 = file.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
               File src = new File(dir,name);
                return src.isFile() && name.endsWith(".java");
            }
        });
        System.out.println(Arrays.toString(files3));
    }
}
